Skip to content

Conversation

@jwnimmer-tri
Copy link
Contributor

On Ubuntu /usr/bin/cc is a symlink to /usr/bin/gcc. Because GCC uses argv[0] to report its --version, that means if the user has set CC=/usr/bin/cc then _is_gcc will return false and the compiler will be mis-detected.

Instead of relying on the binary name, we'll match how Clang detection was already done: run with -v and look for the compiler species in the output. Unlike clang, we'll be slightly more careful by looking for a more specific string, and only on the last line. This is safer because clang -v prints GCC-adjacent details and we don't want that being detected as GCC itself.


On Ubuntu:

jwnimmer@call-cps:~$ ls -l /usr/bin/cc
lrwxrwxrwx 1 root root 20 Jan 31  2024 /usr/bin/cc -> /etc/alternatives/cc
jwnimmer@call-cps:~$ ls -l /etc/alternatives/cc
lrwxrwxrwx 1 root root 12 Jan 31  2024 /etc/alternatives/cc -> /usr/bin/gcc

jwnimmer@call-cps:~$ cc --version | head -n1
cc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
jwnimmer@call-cps:~$ gcc --version | head -n1
gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0

jwnimmer@call-cps:~$ cc -v 2>&1 | tail -n1
gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04) 
jwnimmer@call-cps:~$ gcc -v 2>&1 | tail -n1
gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04) 

@armandomontanez
Copy link
Collaborator

I'm suspicious this will break somebody. Perhaps it would be more conservative to introduce this as a 2nd fallback check instead?

I did confirm this pattern works with arm-none-eabi-gcc, but that's a fairly standard gcc distribution.

On Ubuntu /usr/bin/cc is a symlink to /usr/bin/gcc. Because GCC uses
`argv[0]` to report its `--version`, that means if the user has set
`CC=/usr/bin/cc` then `_is_gcc` will return false and the compiler
will be mis-detected.

Instead of relying on the binary name, we'll match how Clang detection
was already done: run with `-v` and look for the compiler species in
the output. Unlike clang, we'll be slightly more careful by looking
for a more specific string, and only on the last line. This is safer
because `clang -v` prints GCC-adjacent details and we don't want that
being detected as GCC itself.
@jwnimmer-tri
Copy link
Contributor Author

Perhaps it would be more conservative to introduce this as a 2nd fallback check instead?

Fair point. I've pushed that change now.

@armandomontanez armandomontanez added type: bug Something that should be working isn't working P2 We'll consider working on this in future. (Assignee optional) category: toolchains labels Feb 5, 2026
@copybara-service copybara-service bot closed this in 20bf72d Feb 9, 2026
@jwnimmer-tri jwnimmer-tri deleted the gcc-detection branch February 9, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: toolchains P2 We'll consider working on this in future. (Assignee optional) type: bug Something that should be working isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants